package com.xy.zqb.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xy.common.annotation.DataSource;
import com.xy.common.enums.DataSourceType;
import com.xy.common.request.zqb.ZqbUserRequest;
import com.xy.common.utils.bean.BeanUtils;
import com.xy.zqb.service.ZqbUserService;
import com.xy.zqb.entity.ZqbUserEntity;
import com.xy.zqb.mapper.ZqbUserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@DataSource(value = DataSourceType.ZQB)
@Transactional(rollbackFor = Exception.class)
@Service
@Slf4j
public class ZqbUserServiceImpl implements ZqbUserService {
    @Autowired
    private ZqbUserMapper zqbUserMapper;
    @Override
    public List<ZqbUserEntity> list() {
        QueryWrapper<ZqbUserEntity> qryWrapper = new QueryWrapper<>();
        qryWrapper.le("id",20);
        return zqbUserMapper.selectList(qryWrapper);
    }

    @Override
    public Integer count() {
        return zqbUserMapper.selectCount(null);
    }

    @Override
    public Integer add(ZqbUserRequest data) {
        log.info("接收新增数据信息：{}",data);
        ZqbUserEntity add_data=new ZqbUserEntity();
        BeanUtils.copyBeanProp(add_data,data);
        log.info("新增数据：{}",add_data);
//        Integer result=zqbUserMapper.insert(add_data);
//        if(result <= 0){
//            throw new Exception("新增数据失败");
//        }
        return 1;
    }
}
